package link.anyauto.fsmgr.biz.settings;

import android.databinding.DataBindingUtil;

import link.anyauto.fsmgr.R;
import link.anyauto.fsmgr.base.ActBase;
import link.anyauto.fsmgr.base.BaseNames;
import link.anyauto.fsmgr.databinding.ActSettingsBinding;
import link.anyauto.fsmgr.domain.Settings;
import link.anyauto.fsmgr.util.StorageUtil;

/**
 * Created by Administrator on 2016/7/17.
 */
public class ActSettings extends ActBase {

    @Override
    protected void initBinding() {
        binding = DataBindingUtil.setContentView(this, R.layout.act_settings);
    }

    @Override
    protected void initHandlers() {
        handlers = new SettingsHandlers();
        Settings settings = StorageUtil.get(BaseNames.KEY_SETTINGS, Settings.class);
        if(settings == null) {
            settings = new Settings();
        }
        vm = new SettingsVM();
        vm.settings = settings;
        handlers.vm = vm;
    }

    @Override
    protected void postInit() {
        binding.setVm(vm);
        binding.setHandlers(handlers);
    }

    @Override
    protected void unbind() {
        binding.unbind();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        StorageUtil.save(BaseNames.KEY_SETTINGS, vm.settings);
    }

    ActSettingsBinding binding;
    SettingsVM vm;
    SettingsHandlers handlers;
}
